package com.xiaobear.controller;

import com.xiaobear.common.AjaxResult;
import com.xiaobear.common.BaseController;
import com.xiaobear.common.page.TableDataInfo;
import com.xiaobear.domain.GenConfig;
import com.xiaobear.service.IGenConfigService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Version 1.0
 * @ClassName: GenConfigController
 * @Date 2024/3/5 16:28
 * @Description: TODO
 * @Author coffee
 */
@RestController
@RequestMapping("/tool/config")
public class GenConfigController extends BaseController {

    @Resource
    private IGenConfigService genConfigService;

    /**
     * 获取配置列表
     *
     * @param genConfig
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list(GenConfig genConfig) {
        startPage();
        List<GenConfig> list = genConfigService.list(genConfig);
        return getDataTable(list);
    }

    /**
     * 修改配置状态
     *
     * @param genConfig
     * @return
     */
    @PostMapping("/changeState")
    public AjaxResult changeState(@RequestBody GenConfig genConfig) {
        boolean result = genConfigService.changeState(genConfig);
        return toAjax(result);
    }

    /**
     * 修改配置
     *
     * @param genConfig
     * @return
     */
    @PostMapping("/updateConfig")
    public AjaxResult updateConfig(@RequestBody GenConfig genConfig) {
        boolean result = genConfigService.updateConfig(genConfig);
        return toAjax(result);
    }

    /**
     * 添加配置状态
     *
     * @param genConfig
     * @return
     */
    @PostMapping
    public AjaxResult addConfig(@RequestBody GenConfig genConfig) {
        boolean result = genConfigService.addConfig(genConfig);
        return toAjax(result);
    }

    /**
     * 删除配置
     *
     * @param ids
     * @return
     */
    @GetMapping("/delete/{ids}")
    public AjaxResult deleteConfig(@PathVariable Long[] ids) {
        boolean result = genConfigService.deleteConfig(ids);
        return toAjax(result);
    }
}
